#include <bits/stdc++.h>

using namespace std;

class Solution {
public:
	int countElements(vector<int>& nums)
	{
		sort(begin(nums), end(nums));
		int len = size(nums), fi = nums[0], en = nums[len - 1],
			fi_idx = 1, en_idx = len - 2;
		for (; fi_idx < len; fi_idx++) if (nums[fi_idx] != fi) break;
		for (; en_idx > 0; en_idx--) if (nums[en_idx] != en) break;
		return max(0, en_idx - fi_idx + 1);
	}

private:
};

int main()
{
	[[maybe_unused]] Solution solution;
	return 0;
}
